﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;

namespace AUV5.Web
{
    public class PageBaseFrontend : PageBaseTop
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {
            try
            {
                //this.Theme = "Default";
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected override void OnPreInit(EventArgs e)
        {
            //base.OnPreInit 触发 Page_PreInit
            base.OnPreInit(e);
            //this.Theme = "Default";
        }

        protected void Page_PreLoad(object sender, EventArgs e)
        {
            try
            {
                string secret = GetCookiesByKeyName("UserCookie", "Secret");
                if (!string.IsNullOrEmpty(secret))
                {
                    string userId = GetCookiesByKeyName("UserCookie", "UserID");
                    if (string.IsNullOrEmpty(userId))
                        return;

                    string cookieSecret = ConfigurationManager.AppSettings["cookie-secret"];

                    string userName = GetCookiesByKeyName("UserCookie", "UserName");
                    string password = GetCookiesByKeyName("UserCookie", "Password");

                    string finnalSecret = base.EncryptMD5(userId + userName + password + secret).Substring(7, 8);
                    string mysecret = base.EncryptMD5(userId + userName + password + cookieSecret).Substring(7, 8);

                    if (mysecret == secret)
                    {
                        Model.UserInfo user = BLL.UserInfoBLL.Instance.GetDetail(userId);
                        if (user.UserName == userName && user.Password.Substring(7, 8) == password)
                        {
                           base.VerifiedInfo = new AUV5.Model.VerifiedInfo(user);
                        }
                    }
                }
            }
            catch
            { }
        }

        protected override void OnPreLoad(EventArgs e)
        {
            //base.OnPreLoad 触发 Page_PreLoad
            base.OnPreLoad(e);
        }
    }
}